#include "VStdAfx.h"
#include "VRenderResource.h"
#include "VRender.h"
#include "KMTRender.h"
VFastLinkListNode* g_RenderResourceList;
namespace vrc
{
	class RC_ResourceInit : public VRenderCommand
	{
		virtual UINT Execute()
		{
			m_Resource->RT_Init();
			return sizeof(RC_ResourceInit);
		}
		VRenderResource* m_Resource;
	public:
		inline RC_ResourceInit(VRenderResource* Resource) :m_Resource(Resource)
		{
		}
	};

	class RC_ResourceRelease : public VRenderCommand
	{
		virtual UINT Execute()
		{
			m_Resource->RT_Shutdown();
			return sizeof(RC_ResourceRelease);
		}
		VRenderResource* m_Resource;
	public:
		inline RC_ResourceRelease(VRenderResource* Resource) :m_Resource(Resource)
		{
		}
	};

	class RC_ResourceUpdate: public VRenderCommand
	{
		virtual UINT Execute()
		{
			//m_Resource->RT_Update();
			return sizeof(RC_ResourceUpdate);
		}
		VRenderResource* m_Resource;
	public:
		inline RC_ResourceUpdate(VRenderResource* Resource) :m_Resource(Resource)
		{
		}
	};
}

//////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////


void VRenderRefObject::BeginRelease()
{
	VASSERT(m_RefCnt == 0);
	g_Render->MT_BegineReleaseRenderRefObject(this);
}



//////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////
VRenderResource::VRenderResource(void):m_Inited(FALSE)
{
}

VRenderResource::~VRenderResource(void)
{
}

void VRenderResource::InitResource()
{
	if (!m_Inited)
	{
		Link(g_RenderResourceList);
		VASSERT(g_Render);
		VPUSH_RENDER_COMMAND(g_Render, vrc::RC_ResourceInit, (this));
		m_Inited = TRUE;
	}
}

void VRenderResource::ShutdownResource()
{

}
void VRenderResource::UpdateResource()
{
	VASSERT(VEnv.Render);
	VPUSH_RENDER_COMMAND(VEnv.Render, vrc::RC_ResourceUpdate, (this));
}

void VRenderResource::Release()
{
//	VASSERT(VEnv.Render);
//	VPUSH_RENDER_COMMAND(VEnv.Render, vrc::RC_ResourceRelease, (this));
}